<? 
	include('base.php');

	User::protect();

	include_class('links');
	$section = 'links';

	$category_id = $_GET['category_id'];

	$lc = LinkCategory::get($category_id);
	
	if (!db::isError($l)) { 
		switch($_POST['task']) {
			case 'update':
				$res = $lc->update($_POST);
				if (!db::isError($res)) {
					header('Location: links.php?category_id=' . $category_id);
				}
				break;
		}
	}

	$editors = array('description');
	$page_title = 'Edit Link Category';
	include('layout/header.php');
?>

<div id="breadcrumb">
	<a href="index.php">Audition &#62;</a>
	<a href="links.php">Links &#62;</a>

	<?
	$breadcrumb = $lc->getCategoryTrail();

	if ($breadcrumb) { 
		foreach($breadcrumb as $lcBC) {
			echo('<a href="links.php?category_id=' . $lcBC->getID() . '">' . $lcBC->getName() . ' &#62;</a> ');
		}
	}
	if ($lc->error) { ?>
		<br><span class="error">
			<?= $lc->error ?>
		</span> <?
	}
	?>

	Edit Link Category
</div>

<? if (!db::isError($lc)) {

	if (db::isError($res)) {
		$res->outputList();
	}
?>
	
	<h1>edit link category:</h1>
	<div class="inset">
	<form id="edit_entry" action="<?= $PHP_SELF ?>?category_id=<?= $category_id ?>" method="post">
	<input type="hidden" name="task" value="update">
	<div class="edit-form">
		<strong>Name</strong><br/>
		<input type="text" name="name" value="<?= $lc->getName() ?>" class="text">
	</div>
	<div class="edit-form">
		<strong>Description</strong><br/>
		<textarea name="description" class="full" id="description"><?= $lc->getDescription() ?></textarea>
	</div>
	<div class="edit-form">
		<input type="submit" value="Update Link Category" class="button" name="submit">
		<input type="submit" value="Exit Without Updating" class="button" name="preview" onclick="location.href='links.php?category_id=<?= $category_id ?>'; return false">
	</div>
	</div>

<? } else { ?>
	<?= $l->outputDialog('Return to Links', 'links.php') ?>
<? } ?>

<? include('layout/footer.php'); ?>
